package com.group.activity.controller;



import com.github.pagehelper.PageInfo;
import com.group.activity.vo.*;
import com.group.common.utils.StringUtils;
import com.group.common.utils.SymmetricEncoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.group.activity.service.BargainListService;
import com.group.common.utils.R;

import javax.servlet.http.HttpSession;


/**
 * 砍价列表
 *
 * @author gxx
 * @email hongyezhaofang.com
 * @date 2021-11-13 10:36:51
 */
@Slf4j
@RestController
@RequestMapping("activity/bargainlist")
public class BargainListController {
    @Autowired
    private SymmetricEncoder symmetricEncoder;
    @Autowired
    private BargainListService bargainListService;
    @Autowired
    private StringUtils stringUtils;

    /*
    * 消费端 用户砍价
    * */
    @RequestMapping("bargainUser")
    public R bargainUser(@RequestBody BarUserVo barUserVo, HttpSession session){
        Object user = session.getAttribute("loginUser");
        return bargainListService.bargainUser(barUserVo,user);
    }

    /*
    * 消费端 生成帮砍链接
    * */
    @RequestMapping("bargainLink")
    public R bargainLink(Integer bargainingListId,Integer userId ){
        String aesone = symmetricEncoder.AESEncode("AES",String.valueOf(bargainingListId));
        String aestwe = symmetricEncoder.AESEncode("AES",String.valueOf(userId));
        return R.ok().put("data","http://localhost:88/api/activity/bargainlist/helpChop?aesone="+aesone+"&aestwe="+aestwe);
    }
    /*
    * 消费端帮砍人点击帮砍
    * */
    @RequestMapping("helpChop")
    public R helpChop(@RequestParam(value = "aesone",defaultValue = "")String aesone,@RequestParam(value = "aestwe",defaultValue = "") String aestwe, HttpSession session){
        Object user = session.getAttribute("loginUser");
        return bargainListService.helpChop(aesone.replace(" ","+").trim(),aestwe.replace(" ","+").trim(),user);
    }
    /*
    * 后台砍价列表查询
    * */
    @RequestMapping("bargaininglist")
    public R bargaininglist(@RequestBody BargaiListQueryVo bargaiListQueryVo){
        PageInfo<BargainListVo> bargainListVoPageInfo=bargainListService.bargaininglist(bargaiListQueryVo);
        return R.ok().put("data",bargainListVoPageInfo);
    }

    /*
    *后台砍价详情页
    */
    @RequestMapping("bargainingDetails")
    public R bargainingDetails(@RequestBody BargainUserQueryVo bargainUserQueryVo){
        if (stringUtils.isVerification(bargainUserQueryVo.getBargainListId())){
            return R.error("请输入商品列表ID");
        }
        PageInfo<BargainUserVo> bargainUserVoPageInfo=bargainListService.bargainingDetails(bargainUserQueryVo);
        return R.ok().put("data",bargainUserVoPageInfo);
    }

}
